var imgBar = function () {
  //构造当前日期对象
  var date = new Date();
  //获取年份
  var year = date.getFullYear();
  //获取当前月份
  var mouth = date.getMonth() + 1;
  //定义当月的天数；
  var days;
  if (mouth == 2) {
    days = year % 4 == 0 ? 29 : 28;
  } else if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12) {
    //月份为：1,3,5,7,8,10,12 时，为大月.则天数为31；
    days = 31;
  } else {
    //其他月份，天数为：30.
    days = 30;
  }
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('img_Bar'));
  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '每天能源消耗量变化'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#283b56'
        }
      }
    },
    toolbox: {
      show: true,
      feature: {
        dataView: {
          readOnly: false
        },
        restore: {},
        saveAsImage: {}
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: (function () {
        var res = []
        for (var i = 0; i < days; i++) {
          res.push(i + 1);
        }
        return res;
      })()

    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: (function () {
        var scoll = []
        for (var i = 0; i < days; i++) {
          var intdata = 0 + 200 * Math.random();
          scoll.push(intdata);
        }
        return scoll;
      })(),
      type: 'line'
    }]
  };


  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
export default imgBar;
